package com.mohan.dlxj.controller;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.common.R;
import com.mohan.dlxj.pojo.Pole;
import com.mohan.dlxj.pojo.RoleList;
import com.mohan.dlxj.service.PoleService;
import com.mohan.dlxj.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("pole")
public class PoleController {
  @Autowired
  private PoleService poleService;

  @GetMapping("pagePole")
  public JsonResult pagePole(long page,long limit){
    JsonResult jsonResult= poleService.getPoleList(page,limit);
    return jsonResult;
  }

  @GetMapping("getAllNum")
  public R getAllNum() {
    Integer all = poleService.getPoleAll();
    R r = new R();
    r.setData(all);
    r.setCode(200);
    r.setMsg("成功");
    return r;
  }

  @GetMapping("getPoleById/{id}")
  public R getPoleById(@PathVariable Integer id) {
    Pole role = poleService.getPoleById(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("查询成功");
    r.setData(role);
    return r;
  }

  @PostMapping("updatePole")
  public R updatePole(Pole pole) {
    poleService.updatePole(pole);
    R r = new R();
    r.setCode(200);
    r.setMsg("更新电杆成功");
    return r;
  }

  @DeleteMapping("deletePole/{id}")
  public R deletePole(@PathVariable Integer id) {
    poleService.deletePole(id);
    R r = new R();
    r.setCode(200);
    r.setMsg("删除电杆成功");
    return r;
  }


  @PostMapping("savePole")
  public R savePole(Pole pole) {
    poleService.savePole(pole);
    R r = new R();
    r.setCode(200);
    r.setMsg("添加电杆成功");
    return r;
  }

  @PostMapping("updatePoleAll")
  public R updatePoleAll(Pole pole) {
    poleService.updatePoleAll(pole);
    R r = new R();
    r.setCode(200);
    r.setMsg("更新电杆成功");
    return r;
  }
}
